package com.wanqing.assistant.tools;

import com.wanqing.dto.BookPageQueryDTO;
import com.wanqing.entity.Book;
import com.wanqing.result.PageResult;
import com.wanqing.service.BookService;
import com.wanqing.service.OrderService;
import com.wanqing.service.ReportService;
import com.wanqing.vo.*;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.util.List;

@Component
@Slf4j
public class AdminTools {
    @Autowired
    private BookService bookService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private ReportService reportService;

    @Tool(name = "图书库存量", value = "查看所有图书库存量，查询所有图书就不指定图书和分类，不传任何参数。如果查看某一本图书的库存，则传参，但是只传图书名称就行")
    public List bookStock(@P(value = "图书信息", required = false) BookPageQueryDTO bookPageQueryDTO) {
        log.info("图书库存量智能查询被调用");
        PageResult pageResult = bookService.pageQuery(bookPageQueryDTO, false);
        return pageResult.getRecords();
    }

    @Tool(name = "图书库存预警", value = "查看所有库存少于十本的图书，进行预警")
    public List<BookVO> bookStockWarning() {
        log.info("图书库存预警智能查询被调用");
        return bookService.bookStockWarning();
    }

    @Tool(name = "店铺营业额情况", value = "查看一段时期内店铺营业额情况，并给出分析建议")
    public TurnoverReportVO getTurnover(@P(value = "开始时间yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
                                        LocalDate begin,
                                        @P(value = "结束时间yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
                                        LocalDate end) {
        log.info("店铺营业额情况智能查询被调用");
        return reportService.getTurnover(begin, end);
    }

    @Tool(name = "店铺用户情况", value = "查看一段时期内店铺用户情况，并给出分析建议")
    public UserReportVO getUserStatistics(
            @P(value = "开始时间yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @P(value = "结束时间yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {
        log.info("店铺用户情况智能查询被调用");
        return reportService.getUserStatistics(begin, end);
    }

    @Tool(name = "店铺订单情况", value = "查看一段时期内店铺订单情况，并给出分析建议")
    public OrderReportVO getOrderStatistics(
            @P(value = "开始时间yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @P(value = "结束时间yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {
        log.info("店铺订单情况智能查询被调用");
        return reportService.getOrderStatistics(begin, end);
    }

    @Tool(name = "店铺销量前十排名", value = "查看一段时期内店铺销量排名，并给出分析建议")
    public SalesTop10ReportVO getSalesTop10(
            @P(value = "开始时间yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @P(value = "结束时间yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {
        log.info("店铺销量前十排名智能查询被调用");
        return reportService.getSalesTop10(begin, end);
    }

    @Tool(name = "图书智能下架", value = "智能下架图书，根据一段时期内图书销量倒数或者图书缺货时，进行智能下架并返回因为什么原因把哪个图书被下架了。如果只告诉下架缺货的，就不用传参日期了")
    public List<Book> bookDisabled(
            @P(value = "开始时间yyyy-MM-dd", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate begin,
            @P(value = "结束时间yyyy-MM-dd", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd")
            LocalDate end) {
        log.info("图书智能下架被调用");
        return bookService.bookDisabled(begin, end);
    }

}
